package com.ys.controller.api.purchase;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import com.ys.service.purchase.Api1688Service;
import com.ys.vo.R;

/**
 * 1688接口
 * @author XDH
 *
 */
@CrossOrigin
@Controller
@RequestMapping("/api/inter/1688")
public class ApiInter1688Controller {
	@Autowired
	private Api1688Service api1688Service;
	
	/**
	 * 获取订单详情
	 */
	@PostMapping("/get1688ProductDetail")
	@ResponseBody
	public R get1688ProductDetail(String code) throws Exception{
		return api1688Service.get1688ProductDetail(code);
	}
	
	/**
	 * 创建1688订单
	 */
	@PostMapping("/create1688Order")
	@ResponseBody
	public R create1688Order(String orderNos){
		return api1688Service.create1688Order(orderNos);
	}

    /**
     * 取消1688采购订单
     * @param params  格式为{"orderNo":"采购订单号","userId":"0000","cancelReason":""}
     * @return
     */
    @RequestMapping("/cancel1688Order")
    @ResponseBody
    public R cancel1688Order(String orderNos, String cancelReason) {
        try {
            return api1688Service.cancel1688Order(orderNos, cancelReason,true);
        } catch (Exception e) {
            return R.error("ECP_API接口调用取消1688采购订单接口出错，错误为" + e.getMessage());
        }
    }

	/**
	 * 获取1688订单详情信息(对应按钮同步1688信息)
	 * @param orderNos 格式为"orderNos":"采购订单号，多个用逗号隔开"
	 * @return
	 */
	@RequestMapping("/get1688OrderDetail")
	@ResponseBody
	public R get1688OrderDetail(String orderNos)
	{
		try {
			return api1688Service.get1688OrderDetail(orderNos);
		} catch (Exception e) {
			return R.error("ECP_API接口调用获取1688订单详情接口出错，错误为" + e.getMessage());
		}
	}

	/**
	 * 获取1688订单物流跟踪信息(按钮物流完成单的物流轨迹)
	 * @param orderNo  采购订单号
	 * @return
	 */
	@RequestMapping("/get1688OrderTraceInfo")
	@ResponseBody
	public R get1688OrderTraceInfo(String orderNo)
	{
		{
			try {
				return api1688Service.get1688OrderTraceInfo(orderNo);
			} catch (Exception e) {
				return R.error("ECP_API调用获取1688订单物流跟踪信息接口出错，错误为" + e.getMessage());
			}
		}
	}

	/**
	 * 获取1688订单支付URL地址
	 * @param aliOrderNos 1688订单号多个用逗号分开
	 * @return
	 */
	@RequestMapping("/get1688AlipayUrl")
	@ResponseBody
	public R get1688AlipayUrl(String aliOrderNos)
	{
		{
			try {
				return api1688Service.get1688AlipayUrl(aliOrderNos);
			} catch (Exception e) {
				return R.error("ECP_API接口调用获取1688支付URL接口出错，错误为" + e.getMessage());
			}
		}
	}
}
